package router

import (
	"4-7zk/client/client"
	"4-7zk/client/enit"
	"4-7zk/client/response"
	"4-7zk/common/proto/user"
	"github.com/gin-gonic/gin"
)

func Login(c *gin.Context) {
	var data enit.Login
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	login, err := client.Login(c, &user.LoginReq{
		Phone:    data.Phone,
		Password: data.Password,
	})
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	response.ResponseSuccess(c, login)
}
func CourseShow(c *gin.Context) {
	var data enit.Show
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	login, err := client.CourseShow(c, &user.CourseShowReq{
		Id: int64(data.Id),
	})
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	response.ResponseSuccess(c, login)
}
func Reservation(c *gin.Context) {
	ui := c.GetUint("userId")
	var data enit.Reservation
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	reservation, err := client.Reservation(c, &user.ReservationReq{
		UserId:          int64(ui),
		CourseId:        int64(data.CourseId),
		CourseData:      data.CourseData,
		CoursePeoPleNum: int64(data.CoursePeoPleNum),
		ReservationNum:  int64(data.ReservationNum),
		Stadium:         data.Stadium,
		Address:         data.Address,
	})
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	response.ResponseSuccess(c, reservation)
}
func ReservationAdd(c *gin.Context) {
	ui := c.GetUint("userId")
	var data enit.ReservationAdd
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	reservation, err := client.ReservationAdd(c, &user.ReservationAddReq{
		UserId:          int64(ui),
		CourseId:        int64(data.CourseId),
		CourseData:      data.CourseData,
		CoursePeoPleNum: int64(data.CoursePeoPleNum),
		ReservationNum:  int64(data.ReservationNum),
		Stadium:         data.Stadium,
		Address:         data.Address,
		Notes:           data.Notes,
	})
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	response.ResponseSuccess(c, reservation)
}

func ReservationList(c *gin.Context) {
	var data enit.List
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	reservation, err := client.ReservationList(c, &user.ReservationListReq{
		Status: int64(data.Status),
	})
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	response.ResponseSuccess(c, reservation)
}
